package com.project.storage.service;

import com.project.storage.mapper.StorageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: seata-at
 * @description: 库存
 * @author: mml
 * @create: 2023/12/19
 */
@Service
public class StorageService {

    @Autowired
    private StorageMapper storageMapper;

    public boolean deduct(String projectId, Integer count) {
        int deduct = storageMapper.deduct(projectId, count);
        int projectCount = storageMapper.getCount(projectId);
        if (projectCount<0){
            throw  new RuntimeException("库存不足，扣除失败");
        }

        return deduct == 1 ? true : false;
    }
}
